package jin.chen.service.impl;

import jin.chen.mapper.CarouselMapper;
import jin.chen.mapper.CategoryMapper;
import jin.chen.mapper.CategoryMapperCustom;
import jin.chen.pojo.Carousel;
import jin.chen.pojo.Category;
import jin.chen.pojo.vo.CategoryVO;
import jin.chen.pojo.vo.SixNewItemVO;
import jin.chen.service.CarouselService;
import jin.chen.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.persistence.Temporal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private CategoryMapperCustom categoryMapperCustom;
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<Category> queryAllRootType() {
        Example example = new Example(Category.class);
        Example.Criteria criteria = example.createCriteria();
        //type为1 代表分类为根节点
        criteria.andEqualTo("type", 1);
        List<Category> list = categoryMapper.selectByExample(example);
        if(list == null || list.size() < 1){
            return null;
        }
        return list;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<CategoryVO> querySubCatType(Integer rootId) {

        return categoryMapperCustom.getSubCatList(rootId);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<SixNewItemVO> querySixNewItemLazy(Integer rootId) {
        Map<String, Object> map = new HashMap<>();
        map.put("rootCatId", map);
        return categoryMapperCustom.querySixNewItemLazy(rootId);
    }
}
